/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import v4view.web.ext.BindingSelect;

/**
 * Tests all of the elements that implement the IMouseEvents interface.
 * @author J Patrick Davenport
 *
 */
public class MouseEventsTests {
	private static final String	JAVASCRIPT_TEST	= "javascript:test()";
	@SuppressWarnings("rawtypes")
	private List<IMouseEvents>	mouseEvents;

	@SuppressWarnings("rawtypes")
	public MouseEventsTests() {
		this.mouseEvents = new ArrayList<IMouseEvents>();
		this.mouseEvents.add(new A());
		this.mouseEvents.add(new Form());
		this.mouseEvents.add(new Image());
		this.mouseEvents.add(new Li());
		this.mouseEvents.add(new OptGroup());
		this.mouseEvents.add(new Option());
		this.mouseEvents.add(new Select());
		this.mouseEvents.add(new BindingSelect());
		this.mouseEvents.add(new Ul());
		this.mouseEvents.add(new Caption());
		this.mouseEvents.add(new Div());
		this.mouseEvents.add(new P());
		this.mouseEvents.add(new Span());
		this.mouseEvents.add(new Table());
		this.mouseEvents.add(new Tr());
		this.mouseEvents.add(new TBody());
		this.mouseEvents.add(new TFoot());
		this.mouseEvents.add(new THead());
		this.mouseEvents.add(new Td());
		this.mouseEvents.add(new CheckBox());
		this.mouseEvents.add(new File());
		this.mouseEvents.add(new Hidden());
		this.mouseEvents.add(new InputButton());
		this.mouseEvents.add(new InputImage());
		this.mouseEvents.add(new Reset());
		this.mouseEvents.add(new Submit());
		this.mouseEvents.add(new Text());
		this.mouseEvents.add(new Password());
	}

	@SuppressWarnings("rawtypes")
	@Test
	public void testEvents() {
		for (final IMouseEvents e : this.mouseEvents) {
			this.checkMouseOut(e);
			this.checkMouseOver(e);
			this.checkMouseUp(e);
			this.checkOnClick(e);
			this.checkOnDblClick(e);
			this.checkOnMouseDown(e);
			this.checkOnMouseMove(e);
		}
	}

	@SuppressWarnings("rawtypes")
	private void checkOnMouseMove(final IMouseEvents _e) {
		final PageElement setMouseUp = _e.setOnMouseMove(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, _e);
		assertEquals(JAVASCRIPT_TEST, _e.getOnMouseMove());
	}

	@SuppressWarnings("rawtypes")
	private void checkOnMouseDown(final IMouseEvents _e) {
		final PageElement setMouseUp = _e.setOnMouseDown(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, _e);
		assertEquals(JAVASCRIPT_TEST, _e.getOnMouseDown());
	}

	@SuppressWarnings("rawtypes")
	private void checkOnDblClick(final IMouseEvents _e) {
		final PageElement setMouseUp = _e.setOnDblClick(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, _e);
		assertEquals(JAVASCRIPT_TEST, _e.getOnDblClick());
	}

	@SuppressWarnings("rawtypes")
	private void checkOnClick(final IMouseEvents _e) {
		final PageElement setMouseUp = _e.setOnClick(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, _e);
		assertEquals(JAVASCRIPT_TEST, _e.getOnClick());
	}

	@SuppressWarnings("rawtypes")
	private void checkMouseOut(final IMouseEvents e) {
		final PageElement setMouseUp = e.setMouseOut(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, e);
		assertEquals(JAVASCRIPT_TEST, e.getMouseOut());
	}

	@SuppressWarnings("rawtypes")
	private void checkMouseOver(final IMouseEvents e) {
		final PageElement setMouseUp = e.setMouseOver(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, e);
		assertEquals(JAVASCRIPT_TEST, e.getMouseOver());
	}

	@SuppressWarnings("rawtypes")
	private void checkMouseUp(final IMouseEvents e) {
		final PageElement setMouseUp = e.setMouseUp(JAVASCRIPT_TEST);
		assertEquals(setMouseUp, e);
		assertEquals(JAVASCRIPT_TEST, e.getMouseUp());
	}
}
